const express = require('express');
const userController = require('../controllers/user-controller');
const router = express.Router();
const validator = require('../middleware/validator/user-validator');
const { verifyToken } = require('../util/jwt');
const multer = require('multer');
const upload = multer({ dest: 'public/' });
router
  .get('/getchannel', verifyToken(), userController.getchannel)
  .get('/getsubscribe/:userId', verifyToken(), userController.getsubscribe)
  .get('/getuser/:userId', verifyToken(), userController.getuser)
  .post('/registers', validator.register, userController.register)
  .post('/logins', validator.login, userController.login)
  .get('/unsubscribe/:userId', verifyToken(), userController.unsubscribe)
  .get('/subscribe/:userId', verifyToken(), userController.subscribe)
  // upload.single('headimg')中间件处理后会将结果放在下一个中间件的req.file里
  .post('/headimg', verifyToken(), upload.single('headimg'), userController.headimg)
  .get('/lists', verifyToken(), userController.list)
  .put('/', verifyToken(), validator.update, userController.update);

module.exports = router;
